const argv = process.argv

const envIndex = argv.indexOf('-e')
let envConfig = require('./build/env/dev')

if (envIndex != -1) {
  try {
    envConfig = require(`./build/env/${argv[envIndex + 1]}`)
  } catch {
    console.log('获取环境文件出错!')
  }
} else {
  if (process.env.NODE_ENV === 'production') {
    if (argv.includes('prior')) {
      envConfig = require('./build/env/prior')
    } else {
      envConfig = require('./build/env/prod')
    }
  }
}

const targetIndex = argv.indexOf('-t')
let targetConfig = require('./build/target/default')

if (targetIndex != -1) {
  try {
    targetConfig = require(`./build/target/${argv[targetIndex + 1]}`)
  } catch {
    console.log('获取构建目标文件出错!')
  }
}

console.log(`使用的环境为:${envConfig.name},构建目标为:${targetConfig.name}`)

module.exports = { envConfig, targetConfig }
